<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/public/static/h-ui/css/H-ui.min.css"/>
    <script src="/public/js/jquery-2.1.1.js"></script>
    <script src="/public/js/all.js"></script>

</head>
<body>
<article class="cl pd-20">
    <div class="row cl" style="margin-top: 20px;">
        <label class="form-label col-xs-4 col-sm-2">
            <span class="c-red">*</span>
            用户名：</label>
        <div class="formControls col-xs-8 col-sm-8">
            <input type="text" autocomplete="off" value="" onblur="che(this.value)" class="input-text" id="username"
                   style="width:70%;">
        </div>
    </div>
    <div class="row cl" style="margin-top: 20px;">
        <label class="form-label col-xs-4 col-sm-2">
            <span class="c-red">*</span>
            密码：</label>
        <div class="formControls col-xs-8 col-sm-8">
            <input type="password" autocomplete="off" value="" placeholder="至少8位" class="input-text" id="password" style="width:70%;">
        </div>
    </div>
    <div class="row cl" style="margin-top: 20px;">
        <label class="form-label col-xs-4 col-sm-2">
            <span class="c-red">*</span>
            确认密码：</label>
        <div class="formControls col-xs-8 col-sm-8">
            <input type="password" autocomplete="off" value="" placeholder="至少8位" class="input-text" id="repassword" style="width:70%;">
        </div>
    </div>

    </div>

    <div class="row cl" style="margin-top: 30px;">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
            <input class="btn btn-primary radius" onclick="rsave()" type="button"
                   value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
        </div>
    </div>
    <input type="hidden" id="chec" value="0">
</article>
<script type="text/javascript" src="/public/static/layer/2.4/layer.js"></script>
<script type="text/javascript">
    function rsave() {
        var username = $('#username').val();
        var password = $('#password').val();
        var repassword = $('#repassword').val();
        var chec = $('#chec').val();
        if(chec>0){
            layer.msg('用户已存在',{icon:1,time:2000});
        }else {
            $.ajax({
                type: "post",
                url: "__CONF_SITE__admin/role/add_user",
                data: {
                    "username": username,
                    "password": password,
                    "repassword": repassword,
                },
                success: function (data) {
                    if (data['code'] > 0) {
                        layer.msg('添加成功', {icon: 1, time: 2000}, function () {
                            layer_close();
                        });
                    }else{
                        layer.msg(data["message"],{icon:5,time:2000});
                    }
                }
            });
        }
    }
    function che(nn) {
        $.ajax({
            type : "post",
            url : "__CONF_SITE__admin/login/liu",
            data:{
                "username":nn
            },
            success : function(data) {
                $("#chec").val(data);
                if(data>0 ){
                    layer.msg('用户已存在',{icon:5,time:2000});
                }
            }
        });
    }
</script>
</body>
</html>